<template>
  <div class="shop-cart">
    <!-- <h3>{{goods}}</h3> -->
    <!-- <pre>{{goods}}</pre> -->
  </div>
</template>

<script>
import {getHomeGoods} from "network/home.js";
export default {
  name: "ShopCart",
  data() {
    return {
      goods: {
        title: ["流行", "新款", "精品"],
        goodsList: {
          pop: { page: 0, list: [] },
          new: { page: 0, list: [] },
          sell: { page: 0, list: [] }
        },
        currentType: "pop"
      }
    };
  },
  methods: {
    // async fetchHomeDoodsData(type) {
    //   // page+1
    //   this.goods.goodsList[type].page++;
    //   await getHomeGoods(type, this.goods.goodsList[type].page).then(res => {
    //     //把数据追加到列表中
    //     console.log(res);
    //     this.goods.goodsList[type].list.push(...res.data.list);
    //   });
    // },
    async feachHomeGoods(type) {
      // 页码+1
      this.goods.goodsList[type].page++;
      await getHomeGoods(type, this.goods.goodsList[type].page).then(res => {
        // this.goods[type].list=this.goods[type].list.concat(res.data.list)
        // 把请求到数据追加列表中
        this.goods.goodsList[type].list.push(...res.data.list);
      });
    }
  },
  components: {},
  computed: {},
  watch: {},
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    
    Object.keys(this.goods.goodsList).forEach(element => {
      this.feachHomeGoods(element);
    });
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  updated() {}, //生命周期 - 更新之后
  activated() {} //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='less' scoped>
//@import url(); 引入公共css类
</style>